package com.jn.exam.exam.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jn.exam.exam.entity.Exam;
import com.jn.exam.exam.entity.Student;
import com.jn.exam.exam.entity.Teacher;
import com.jn.exam.exam.entity.vo.ExamStudentVo;

import com.jn.exam.exam.mapper.ExamMapper;
import com.jn.exam.exam.service.ExamService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 江南大学1033190417
 * @since 2022-02-18
 */
@Service
public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements ExamService {
    //学生报名考试
    @Override
    public boolean registerForExam(Map<String, Object> param) {
        return baseMapper.registerForExam(param);
    }

    //查询某学生参加的考试
    @Override
    public List<String> getStudentExamIds(String studentId) {
        return baseMapper.getStudentExamIds(studentId);
    }


    //查询参加某场考试的所有学生
    @Override
    public List<Student> getAllStudentForExam(String examId) {
        return baseMapper.getAllStudentForExam(examId);
    }


    @Override
    public boolean saveExam(Exam exam) {
        return baseMapper.saveExam(exam);
    }

    @Override
    public boolean addExamProctor(Map<String, Object> param) {
        return baseMapper.addExamProctor(param);
    }

    @Override
    public boolean addExamMarking(Map<String, Object> param) {
        return baseMapper.addExamMarking(param);
    }

    @Override
    public boolean removeProctor(String examId, String teacherId) {
        return baseMapper.removeProctor(examId, teacherId);
    }

    @Override
    public boolean removeMarking(String examId, String teacherId) {
        return baseMapper.removeMarking(examId, teacherId);
    }

    @Override
    @Transactional
    public boolean deleteExam(String examId) {
        boolean isOK5 = baseMapper.updatePaperStatus(examId);
        //删除监考老师
        boolean isOK1 = baseMapper.removeMarkings(examId);
        //删除阅卷老师
        boolean isOK2 = baseMapper.removeProctors(examId);
        //删除考试与学生联系
        boolean isOK3 = baseMapper.removeExamStudent(examId);
        //删除人脸违规
        boolean isOK4 = baseMapper.removeViolation(examId);
        int i = baseMapper.deleteById(examId);
        //讲试卷改为科发布考试阶段

        return true;
    }

    @Override
    public List<String> getExamIds(String teacherId) {
        return baseMapper.getExamIds(teacherId);
    }

    @Override
    public boolean leaveExam(String studentId, String examId) {
        return baseMapper.leaveExam(studentId, examId);
    }

    @Override
    public List<String> getMyProctorExamIds(String teacherId) {
        return baseMapper.getMyProctorExamIds(teacherId);
    }

    @Override
    public List<Teacher> getProctorTeacher(String examId) {
        return baseMapper.getProctorTeacher(examId);
    }

    @Override
    public List<Teacher> getMarkingTeacher(String examId) {
        return baseMapper.getMarkingTeacher(examId);
    }

    @Override
    public List<String> getMyMarkingExamIds(String teacherId) {
        return baseMapper.getMyMarkingExamIds(teacherId);
    }

    @Override
    public Integer getPageStudentForExamTotal(ExamStudentVo examStudentVo) {
        return baseMapper.getPageStudentForExamTotal(examStudentVo);
    }

    @Override
    public List<Student> getPageStudentForExam(ExamStudentVo examStudentVo) {
        return baseMapper.getPageStudentForExam(examStudentVo);
    }


    @Override
    public Integer isAttendedForExam(String examId, String studentId) {
        Map<String, Object> param = new HashMap<>();
        param.put("examId", examId);
        param.put("studentId", studentId);
        return baseMapper.isAttendedForExam(param);
    }

    @Override
    public boolean updateAttendFormExam(String examId, String studentId, Integer status) {
        Map<String, Object> param = new HashMap<>();
        param.put("examId", examId);
        param.put("studentId", studentId);
        param.put("status", status);
        return baseMapper.updateAttendFormExam(param);
    }

    @Override
    public boolean cheatStudent(String examId, String studentId, boolean isCheated) {
        Map<String, Object> param = new HashMap<>();
        param.put("examId", examId);
        param.put("studentId", studentId);
        param.put("isCheated", isCheated);
        return baseMapper.cheatStudent(param);
    }

    @Override
    public List<Map<String, Object>> getAllStudentAttendStatusOfExam(String examId) {
        return baseMapper.getAllStudentAttendStatusOfExam(examId);
    }

    @Override
    public List<Map<String, Object>> queryNumberOfPerScore(String examId) {
        return baseMapper.queryNumberOfPerScore(examId);
    }
}
